home *** CD-ROM | disk | FTP | other *** search
/ Toy Story Activity Center / Toy Story Activity Center (Disney-Pixar)(B0496)(1996).ISO / mac / Sound Manager 3.2 / Sound 3.2 release notes < prev    next >
Text File  |  1996-03-04  |  19KB  |  301 lines

  1. Sound Manager 3.2 New Features
  2. March, 1996
  3.  
  4. Sound Manager 3.2 contains some new routines for determining sound formats and converting between sound formats. This document describes the application programming interface to these new features and the bug fixes.
  5.  
  6. Determining Sound Hardware Settings
  7.  
  8. New Sound Manager routines: GetSoundOutputInfo() and SetSoundOutputInfo().
  9.  
  10. Two routines have been added to get and set information about the sound environment: GetSoundOutputInfo() and SetSoundOutputInfo. Both routines use a selector-based interface similar to the SPBGetDeviceInfo/SPBSetDeviceInfo routines found in the Sound Input Manager, and in fact they use the same selectors.
  11.  
  12. GetSoundOutputInfo() and SetSoundOutputInfo() operate directly on a sound output device, and can be used to retrieve and change information about the hardware settings. These routines should be used instead of attempting to communicate directly with sound output components. Setting the output device parameter to nil causes the default output device to be used. These calls are similar to GetSndInfo() and SetSndInfo() but do not require an opened sound channel.
  13.  
  14. pascal OSErr GetSoundOutputInfo(Component outputDevice, OSType selector, void *infoPtr);
  15.  
  16. pascal OSErr SetSoundOutputInfo(Component outputDevice, OSType selector, const void *infoPtr);
  17.  
  18. These new calls are only available with Sound Manager version 3.1 or later. Check for this by calling SndSoundManagerVersion() for the installed version.
  19.  
  20. For example, to determine the sampling rate of the sound hardware on the default output device, you could use this code:
  21.  
  22. OSErr GetCurrentSampleRate(UnsignedFixed *sampleRate)
  23. {
  24.     OSErr           err;
  25.  
  26.     err = GetSoundOutputInfo(nil, siSampleRate, sampleRate);
  27.     return (err);
  28. }
  29.  
  30. Determining Sound Formats
  31.  
  32. pascal OSErr ParseAIFFHeader(short fRefNum, SoundComponentData *sndInfo,
  33.                        unsigned long *numFrames, unsigned long *dataOffset)
  34.  
  35. ParseAIFFHeader returns information describing the audio data in the given AIFF file. The fRefNum parameter specifies the open AIFF file to use. The sndInfo parameter is a SoundComponentData structure that returns the following information about the format of the sound in the AIFF file:
  36.  
  37.     flags           - always returns 0
  38.     format          - the sound format (i.e. 'raw ', 'twos', 'MAC3', etc.)
  39.     numChannels     - the number of channels  (i.e. 1 = mono, 2 = stereo)
  40.     sampleSize      - the sample size (i.e. 8 = 8-bit, 16 = 16-bit)
  41.     sampleRate      - the sampling rate (in samples/second)
  42.     sampleCount     - the number of audio samples in the file
  43.     buffer          - always returns 0
  44.     reserved        - always returns 0
  45.  
  46. The numFrames parameter returns the number of frames of audio data in the file, and the dataOffset parameter returns the byte offset of the first audio sample in the file.
  47.  
  48. Errors:
  49.     siInvalidCompression    - compression type not supported
  50.     badFileFormat           - file does not contain valid AIFF data
  51.  
  52. pascal OSErr ParseSndHeader(SndListHandle sndHandle, SoundComponentData *sndInfo,
  53.                        unsigned long *numFrames, unsigned long *dataOffset)
  54.  
  55. ParseSndHeader returns information describing the audio data in the given 'snd ' resource handle. The sndHandle parameter specifies the sound handle to use. The sndInfo parameter is a SoundComponentData structure that returns the following information about the format of the sound in the handle:
  56.  
  57.     flags           - always returns 0
  58.     format          - the sound format (i.e. 'raw ', 'twos', 'MAC3', etc.)
  59.     numChannels     - the number of channels  (i.e. 1 = mono, 2 = stereo)
  60.     sampleSize      - the sample size (i.e. 8 = 8-bit, 16 = 16-bit)
  61.     sampleRate      - the sampling rate (in samples/second)
  62.     sampleCount     - the number of audio samples in the handle
  63.     buffer          - always returns 0
  64.     reserved        - always returns 0  
  65.  
  66. The numFrames parameter returns the number of frames of audio data in the handle, and the dataOffset parameter returns the byte offset of the first audio sample in the handle.
  67.  
  68. Errors:
  69.         siInvalidCompression    - compression type not supported
  70.     badFormat               - file does not contain valid 'snd ' data
  71.     nilHandleErr             - a nil handle was passed
  72.  
  73. pascal OSErr GetCompressionName(OSType compressionType, Str255 compressionName)
  74.  
  75. GetCompressionName returns a string describing the given compression format in a string that can be displayed to the user. The compressionType parameter specifies the compression format, and the name is returned in compressionName. This string can be used in pop-up menus and other user interface elements to allow the user to select a compression format.
  76.  
  77. Errors:
  78.     memFullErr              - not enough memory to load name
  79.     siInvalidCompression    - compression type not supported
  80.     resNotFound             - compression name not available
  81.  
  82. Converting Sounds
  83.  
  84. An architecture has been added to Sound Manager 3.2 to allow you to easily convert between sound formats. Some of the operations that can be performed are compression, decompression, channel conversion, sample rate conversion and sample format conversion.
  85.  
  86. A conversion session is begun by calling SoundConverterOpen, to which you pass the format of the sound to be converted and the resulting output format. A SoundConverter identifier is returned that must be passed to all further routines in this session. SoundConverterClose is used to close the session.
  87.  
  88. SoundConverterGetBufferSizes allows you to determine input and output buffer sizes based on a target buffer size. This lets you create buffers to fit the conversion established with SoundConverterOpen.
  89.  
  90. Converting a sound is a three-step process. First, you call SoundConverterBeginConversion to initiate the conversion and reset the SoundConverter to default settings. Then SoundConverterConvertBuffer is called one or more times to convert sequential buffers of the input data to the output format. Finally, when all input data has been converted, SoundConverterEndConversion flushes out any data left in the converter.
  91.  
  92. pascal OSErr SoundConverterOpen(const SoundComponentData *inputFormat,
  93.                      const SoundComponentData *outputFormat, SoundConverter *sc)
  94.  
  95. SoundConverterOpen sets up the conversion session and returns a SoundConverter identifier to be passed to all further routines. The inputFormat parameter specifies the format of the sound data to be converted using a SoundComponentData structure. The following fields must be set up to describe the sound correctly:
  96.  
  97.     flags           - set to 0
  98.     format          - the sound format (i.e. 'raw ', 'twos', 'MAC3', etc.)
  99.     numChannels     - the number of channels  (i.e. 1 = mono, 2 = stereo)
  100.     sampleSize      - the sample size (i.e. 8 = 8-bit, 16 = 16-bit)
  101.     sampleRate      - the sampling rate (in samples/second)
  102.     sampleCount     - set to 0
  103.     buffer          - set to 0
  104.     reserved        - set to 0  
  105.  
  106. The outputFormat parameter specifies the output format, and must be passed fields similar to inputFormat. Output fields that are different from input fields will cause a conversion. For example, if the input sound format is 'raw ' and the output format is 'MAC3', the data resulting from the conversion will be compressed with MACE 3:1. This allows any combination of compression, decompression, channel conversion, sample size conversion and sampling rate conversion. A SoundConverter identifier is returned to manage the session, which must be passed to all further routines.
  107.  
  108. This routine cannot be called at interrupt time.
  109.  
  110. Errors:
  111.     memFullErr              - not enough memory
  112.     siInvalidCompression    - compression type not supported
  113.     siInvalidSampleSize     - sample size not supported
  114.  
  115. pascal OSErr SoundConverterClose(SoundConverter sc)
  116.  
  117. SoundConverterClose terminates the session and frees up all memory and services associated with this session.
  118.  
  119. This routine cannot be called at interrupt time.
  120.  
  121. Errors:
  122.     none
  123.  
  124. pascal OSErr SoundConverterGetBufferSizes(SoundConverter sc, unsigned long targetBytes,
  125.                      unsigned long *inputFrames, unsigned long *inputBytes,
  126.                      unsigned long *outputBytes)
  127.  
  128. SoundConverterGetBufferSizes is used to determine the input and output buffer sizes for a given target size. This is so you can make sure your buffers will fit the conversion parameters established with SoundConverterOpen.
  129.  
  130. The targetBytes parameter is the approximate number of bytes you would like both your input and output buffers to be. The inputFrames and inputBytes parameters return the actual size you should make your input buffer, in frames and bytes respectively. The outputBytes parameter returns the size in bytes for your output buffer.
  131.  
  132. Note: The returned input and output buffer sizes CAN be larger than your target size settings. This is because they are rounded up depending on the format, but they will be very close to the target settings. Also note that the input and output sizes may be very different, depending on the input and output formats given in SoundConverterOpen. The sizes are calculated assuming you will convert all data in the input buffer to the output buffer.
  133.  
  134. This routine cannot be called at interrupt time.
  135.  
  136. Errors:
  137.     notEnoughBufferSpace    - input bytes target too small
  138.     
  139.  
  140. pascal OSErr SoundConverterBeginConversion(SoundConverter sc)
  141.  
  142. SoundConverterBeginConversion starts a conversion. All state information is reset to default values in preparation for a new input buffer.
  143.  
  144. This routine can be called at interrupt time.
  145.  
  146. Errors:
  147.     none
  148.  
  149. pascal OSErr SoundConverterConvertBuffer(SoundConverter sc, const void *inputPtr,
  150.                      unsigned long inputFrames, void *outputPtr,
  151.                      unsigned long *outputFrames, unsigned long *outputBytes)
  152.  
  153. SoundConverterConvertBuffer converts a buffer of data from the input format to the output format. The inputPtr parameter points to the input data, and inputFrames gives the number of frames in that buffer. The outputPtr parameter specifies where the output data should be placed. The output Frames and outputBytes parameters return the number of frames and bytes placed in the output buffer respectively.
  154.  
  155. This routine will consume all the data in the input buffer, but, depending on the complexity of the conversion, not all the converted data may be put in the output buffer right away. The SoundConverterEndConversion routine is used to flush out all this remaining data before a conversion session is closed.
  156.  
  157. If you are using this routine in conjunction with SoundConverterGetBufferSizes, it is very important that you do not pass in a value in inputFrames larger than the frames value returned by SoundConverterGetBufferSizes, or you will overflow your output buffer. The SoundConverterConvertBuffer calls converts ALL the input data!
  158.  
  159. This routine can be called at interrupt time.
  160.  
  161. Errors:
  162.     none
  163.  
  164. pascal OSErr SoundConverterEndConversion(SoundConverter sc, void *outputPtr,
  165.                      unsigned long *outputFrames, unsigned long *outputBytes)
  166.  
  167. SoundConverterEndConversion ends a conversion. Any data remaining in the converters is flushed out and returned here.
  168.  
  169. This routine can be called at interrupt time.
  170.  
  171. Errors:
  172.     none
  173.  
  174. Conversion Example
  175.  
  176. The following is an example of how to use the sound conversion architecture to convert a buffer of silence to IMA 4:1, changing the sampling rate in the process.
  177.  
  178. enum {
  179.     kTargetBytes = 20 * 1024
  180. };
  181.  
  182. void main(void)
  183. {
  184.     SoundConverter      sc;
  185.     SoundComponentData  inputFormat, outputFormat;
  186.     unsigned long       inputFrames, inputBytes;
  187.     unsigned long       outputFrames, outputBytes;
  188.     Ptr                 inputPtr, outputPtr;
  189.     OSErr               err;
  190.     
  191.     inputFormat.flags = 0;
  192.     inputFormat.format = kOffsetBinary;
  193.     inputFormat.numChannels = 1;
  194.     inputFormat.sampleSize = 8;
  195.     inputFormat.sampleRate = rate22050hz;
  196.     inputFormat.sampleCount = 0;
  197.     inputFormat.buffer = nil;
  198.     inputFormat.reserved = 0;
  199.  
  200.     outputFormat.flags = 0;
  201.     outputFormat.format = 'ima4';
  202.     outputFormat.numChannels = 1;
  203.     outputFormat.sampleSize = 16;
  204.     outputFormat.sampleRate = rate44100hz;
  205.     outputFormat.sampleCount = 0;
  206.     outputFormat.buffer = nil;
  207.     outputFormat.reserved = 0;
  208.  
  209.     err = SoundConverterOpen(&inputFormat, &outputFormat, &sc);
  210.     if (err != noErr)
  211.         DebugStr("\pOpen failed");
  212.  
  213.     err = SoundConverterGetBufferSizes(sc, kTargetBytes,
  214.                     &inputFrames, &inputBytes, &outputBytes);
  215.     if (err != noErr)
  216.         DebugStr("\pGetBufferSizes failed");
  217.  
  218.     inputPtr = NewPtrClear(inputBytes);
  219.     outputPtr = NewPtrClear(outputBytes);
  220.  
  221.     // fill input buffer with 8-bit silence
  222.     {
  223.         int     i;
  224.         Ptr     dp = inputPtr;
  225.  
  226.         for (i = 0; i < inputBytes; i++)
  227.             *dp++ = 0x80;
  228.     }
  229.  
  230.     err = SoundConverterBeginConversion(sc);
  231.     if (err != noErr)
  232.         DebugStr("\pBegin Conversion failed");
  233.  
  234.     err = SoundConverterConvertBuffer(sc, inputPtr, inputFrames,
  235.                     outputPtr, &outputFrames, &outputBytes);
  236.     if (err != noErr)
  237.         DebugStr("\pConversion failed");
  238.  
  239.     err = SoundConverterEndConversion(sc,
  240.                     outputPtr,&outputFrames, &outputBytes);
  241.     if (err != noErr)
  242.         DebugStr("\pEnd Conversion failed");
  243.  
  244.     err = SoundConverterClose(sc);
  245.     if (err != noErr)
  246.         DebugStr("\pClose failed");
  247. }
  248.  
  249.  
  250. Bugs Fixed/New Features
  251.  
  252. Sound Output
  253.  
  254. New version of InstallMoveHHiPatch that will install on PowerMacs when the old Memory Manager is running. On PowerMacs with our new native PowerPC sound components we use more than 3k of the stack. The MoveHHi() in the new ROMs will only preserve 3k so we have to patch it to preserve more stack space.
  255.  
  256. Use a nil sound output component reference to specify the default device when calling Get/SetSoundOutputInfo().
  257.  
  258. Deal with left over samples during compression better by preserving them across calls to PlaySourceBuffer(). This allows sequential calls to a compressor with non-packet multiple buffer sizes to seam together without clicks.
  259.  
  260. Fixed SetSource() in the format converter so it does not ask the source for 8-bit twos-complement data, which no other sound component supports. This fixes problems when the format converter is installed after the mixer and is asked to output 8-bit twos.
  261.  
  262. In the sample rate converter the samplesToSkip field now stores the amount to skip into a new buffer. The byteOffset field is updated to this value when a new buffer is received. This fixes a problem playing scales with the freqDuration command when a new buffer is played before the old buffer has reached the end.
  263.  
  264. The gestaltSoundAttr proc being installed needs to avoid using unknown CPUs or re-cycled machine types.
  265.  
  266. Sound Input
  267.  
  268. siSetupCDAudio
  269.  
  270. This selector is only used by input devices that have special requirements in order to hear the audio from the CD player. For example, currently the 840AV and PowerMacs require the user to open the Sound control panel, select the Inputs panel, and then open the Options dialog. From here they have to select the CD Input and also check the Play-Through option. The new siSetupCDAudio avoids this troublesome operation by setting up the input device to allow you to hear audio CDs from the audio CD player.
  271.  
  272. The infoData parameter points to a short word. A value of 1 means to setup the hardware (e.g. set input source to CD and turn on Play-Through). A value of 0 means to return the input hardware to some initial state, either the default settings or the settings prior to setting up for the CD audio. Any other value is an error. If the input device had no special needs for CD audio (e.g. the audio is heard regardless of the input hardware settings) then the selector is not supported and it returns an error. The SPBGetDeviceInfo() should return a 1 or 0 value depending on its current setting. If the input source is the CD and Play-Through, if required, is on, then return the value of 1. This should happen even if nothing ever requested setting up for CD audio. It should return the state of the actual condition of the input hardware.
  273.  
  274. Multiply bytesPerSample by 8 to get sampleSize for sound header. Fixes bug in SetupSndHeader with arbitrary compression formats.
  275.  
  276. Hardware
  277.  
  278. siHardwareVolume
  279.  
  280. This output selector was previously defined, but should be documented and implemented as returning the volume of the device that can be heard. For example, the PowerMac can have the speaker and the headphones both be audible to the user. In this case, return the loudest volume setting. If both the speaker and the headphones are muted, then again return the loudest setting. If one is muted and the other is audible, then return the volume of the audible source.
  281.  
  282. siHardwareMute
  283.  
  284. This output selector was previously defined, but should be documented and implemented as returning the mute state of all sources that can be heard. For example, the PowerMac has a speaker and headphone source. If no headphones are plugged in, then return the mute state of the speakers. If headphones are inserted, then return the mute state of both (e.g. siHardwareMute is muted when both speakers and headphones are muted). The idea is if the user has sources that can be heard and all are muted, then the hardware has been muted. If any one of the sources can be heard, then the hardware is not muted.
  285.  
  286. siHardwareBusy
  287.  
  288. Used by all input and output devices. This returns the state of the hardware. Typically, this means whether or not the hardware interrupts are active. For input devices, the infoData parameter points to a short word. For output devices, the infoPtr is a short word containing the value. A value of 0 represents that the hardware is not busy, whereas 1 represents busy. This selector is only supported by the get calls, since it doesn't make since to "set" a device busy.
  289.  
  290. Fixed the siHardwareBusy selector in the 8500 series.
  291.  
  292. Added speaker and headphone muting into the preferences. This allows for the user to specify the speaker is no muted when using external speakers or headphones, and the next time the machine is started the user's preference is restore. Previously it would default to always muting the speaker if something was inserted into the headphone jack.
  293.  
  294. Preserve register A0 within DetermineInputSource() when calling GetInitialPreferences().
  295.  
  296. Interfaces
  297.  
  298. SndSoundManagerVersion(), SPBVersion(), and MACEVersion() should all return a NumVersion. A recent version of the interfaces were changed to return an unsigned long, but this fails with creating native PowerPC code.
  299.  
  300. A new version of SoundLib has been released to include all of the new Sound Manager 3.2 API.
  301.